<template>
  <div class="comment-post">
    <van-field
      class="post-field"
      v-model.trim="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入留言"
      show-word-limit
    />
    <van-button @click="SendComment" :disabled="!message.length" class="post-btn">发布</van-button>
  </div>
</template>

<script>
import { CommentlAPI } from '@/api/comment.js'
export default {
  name: 'CommentPost',
  components: {},
  props: {
    articleID: {

      type: [Object, Number, String],
      required: true
    }
  },
  data () {
    return {
      message: ''
    }
  },
  computed: {},
  watch: {},

  methods: {
    async SendComment () {
      if (this.message) {
        const { data } = await CommentlAPI({
          target: this.articleID, // 文章的 id
          content: this.message// 评论的内容
        })

        // 发送完后关闭窗口
        this.$emit('post-success', data)
        this.message = ''
      } else {
        this.$toast('内容不能为空')
      }
    }
  }
}
</script>

<style scoped lang="less">
.comment-post {
  display: flex;
  align-items: center;
  padding: 32px 0 32px 32px;
  .post-field {
    background-color: #f5f7f9;
  }
  .post-btn {
    width: 150px;
    border: none;
    padding: 0;
    color: #6ba3d8;
    &::before {
      display: none;
    }
  }
}
</style>
